import axios from 'axios'
axios.defaults.withCredentials = true
axios.defaults.baseURL = ''
axios.defaults.timeout = 5000
axios.defaults.headers = {
  'Content-Type': 'application/json;charset=UTF-8'
}

// request全局拦截
axios.interceptors.request.use(
  config => {
    return Promise.resolve(config)
  },
  error => {
    return Promise.reject(error)
  }
)

// response全局拦截
axios.interceptors.response.use(
    response => {
        return response
    },
    error => {
        return Promise.resolve(error.response)
    }
)

export const post = (url, params = '') => {
  return axios({
    method: 'post',
    url: url,
    data: params
  })
}

export const get = (url, params = '') => {
  return axios({
    method: 'get',
    url: url,
    params: params
  })
}

export const download = (url, params = '') => {
    return axios({
        method: 'post',
        url: url,
        params: params,
        responseType: 'arraybuffer'
    })
}
